package com.ysstech.reportworld.service.impl;

import com.ysstech.reportworld.entity.DataDemandBug;
import com.ysstech.reportworld.mapper.DataDemandBugMapper;
import com.ysstech.reportworld.service.DataDemandBugService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 报表世界数据和需求BUG关联关系表 服务实现类
 * </p>
 *
 * @author lishuangliang
 * @since 2022-12-27
 */
@Service
public class DataDemandBugServiceImpl extends ServiceImpl<DataDemandBugMapper, DataDemandBug> implements DataDemandBugService {

    @Override
    public Map<String, List<String>> getDataDemandBugMap() throws Exception {
        // 需求BUG code和数据，对应一个list
        List<DataDemandBug> dataDemandBugList = this.list();
        if (CollectionUtils.isEmpty(dataDemandBugList)) {
            return null;
        }
        Map<String, List<String>> mapDataDemandBug = new HashMap<>();
        for (DataDemandBug demandBug : dataDemandBugList) {
            if (null == demandBug || StringUtils.isBlank(demandBug.getDataId()) || StringUtils.isBlank(demandBug.getDataCode())) {
                continue;
            }
            String key = demandBug.getDataCode() + "\t" + demandBug.getDataId();
            if (mapDataDemandBug.containsKey(key)) {
                List<String> list = mapDataDemandBug.get(key);
                list.add(demandBug.getDemandBugId());
                mapDataDemandBug.put(key, list);
            } else {
                List<String> list = new ArrayList<>();
                list.add(demandBug.getDemandBugId());
                mapDataDemandBug.put(key, list);
            }
        }
        return mapDataDemandBug;
    }
}
